package com.dazzle.core.util.common;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ResourceBundleMessageSource;

public class AppUtil implements ApplicationContextAware{

	
	private static ApplicationContext appContext;
	
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.appContext = applicationContext;
	}

	
	/**
	 * 取得Bean
	 * @param beanId
	 * @return
	 */
	public static Object getBean(String beanId){
		return appContext.getBean(beanId);
	}
	
	public static String getMessage(String code,Object[] args,HttpServletRequest request){
		Locale locale = request.getLocale();
		ResourceBundleMessageSource rbmSource = (ResourceBundleMessageSource)getBean("messageSource");
		return rbmSource.getMessage(code, args, locale);
	}
}
